package com.news.gpb.dao;

import com.news.gpb.entity.Coll;
import com.news.gpb.entity.Like;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface LikeDao {

    @Select("select * from likes where user_id=#{like.user_id} and news_id=#{like.news_id}")
    Integer getLike(@Param("like")Like like);

    @Insert("insert into likes (user_id,news_id) values(#{like.user_id},#{like.news_id})")
    @Options(useGeneratedKeys = true,keyProperty = "like.like_id",keyColumn = "like_id")
    Integer likeUp(@Param("like") Like like);

    @Delete("delete from likes where user_id=#{like.user_id} and news_id=#{like.news_id}")
    Integer likeDown(@Param("like") Like like);

    @Select("select count(*) from likes where user_id=#{user_id}")
    Integer countLike(@Param("user_id") int user_id);

    @Select("select news_id from likes where user_id=#{user_id} order by like_time desc")
    List<Integer> getMyLike(@Param("user_id")int user_id);
}
